/**
 * Captain
 * © 2018 Captain copyright，All rights reserved.
 * http://www.sccaptain.com.cn
 * 
 * JAVA : 8
 * 文  件  名: AccountController.java
 * 创  建  人: QinYoubin (qin.youbin@sccaptain.com.cn)
 * 创建时间: 2018年5月3日 下午2:08:39
 * 版         本: 1.0.0
 * 备         注:
 * 修订历史:
 */
package com.material.c2c.web.user.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cpt.framework.web.JsonResult;

/**
 * 获取当前用户的接口
 * @since 1.0
 * @version 1.0
 * @author QinYoubin (qin.youbin@sccaptain.com.cn)
 */
@RestController
@RequestMapping("/sys/sec")
public class AccountController {
  
  @Autowired
  private HttpServletRequest request;
  
  @GetMapping("/getMe")
  public JsonResult getMe() {
    // 获取当前登录用户
    Map<String,Object> res = new HashMap<String,Object>();
    HttpSession session = request.getSession();
    Object adminObj= session.getAttribute("admin");
    Object userObj = session.getAttribute("user");
    if(adminObj == null && userObj==null) {
      res.put("loginStatus", false);
    } else {
      if(userObj != null) {
        res.put("role", "user");
        res.put("detail", userObj);
      } 
      if(adminObj != null) {
        res.put("role", "admin");
        res.put("detail", adminObj);
      }
      res.put("loginStatus", true);
    }
    return JsonResult.success(res);
  }
}
